package com.base.dp;

public class MostPoints {
    public static void main(String[] args) {
        MostPoints mostPoints = new MostPoints();
        System.out.println(mostPoints);
    }


    public long mostPoints(int[][] questions) {
        int n = questions.length;
        int[] dp = new int[n + 1];  // 使用 n+1 以便处理边界情况

        for (int i = n - 1; i >= 0; i--) {  // 从后往前遍历
            int points = questions[i][0];
            int brainpower = questions[i][1];
            // 选择解决当前问题
            int solve = points + (i + brainpower + 1 < n ? dp[i + brainpower + 1] : 0);
            // 选择跳过当前问题
            int skip = dp[i + 1];
            // 更新 dp[i]
            dp[i] = Math.max(solve, skip);
        }

        return dp[0];  // 返回解决第一个问题后的最高分数
    }
}
